﻿using Chain.BLL;
using Chain.Model;
using Chain.Tasks;
using System;
using System.Data;
using System.Xml;

public partial class AutoSendSMSByMemBirthday : ITask
{
    public void Execute(XmlNode node)
    {
        if ((PubFunction.curParameter.bolIsAutoSendSMSByMemBirthday && PubFunction.curParameter.bolSms) && (Convert.ToInt32(SMSInfo.GetBalance(false)) > 0))
        {
            Chain.BLL.Mem MemBll = new Chain.BLL.Mem();
            Chain.BLL.MemberSMSRemindLog MemberSMSRemindLogBll = new Chain.BLL.MemberSMSRemindLog();
            DataTable dtMem = MemBll.GetMemBirthday(PubFunction.curParameter.intAutoSendSMSByMemBirthdayForDay).Tables[0];
            DataTable dtLog = MemberSMSRemindLogBll.GetMemBirthdayed().Tables[0];
            if ((dtMem != null) && (dtMem.Rows.Count > 0))
            {
                for (int i = 0; i < dtMem.Rows.Count; i++)
                {
                    if ((dtLog.Select("MemberSMSRemindMemID=" + dtMem.Rows[i]["MemID"]).Length == 0) && (Convert.ToInt32(SMSInfo.GetBalance(false)) > 0))
                    {
                        SmsTemplateParameter smsTemplateParameter = new SmsTemplateParameter();
                        smsTemplateParameter.strCardID = dtMem.Rows[i]["MemCard"].ToString();
                        smsTemplateParameter.strName = dtMem.Rows[i]["MemName"].ToString();
                        smsTemplateParameter.dclMoney = Convert.ToDecimal(dtMem.Rows[i]["MemMoney"]);
                        smsTemplateParameter.dclTempMoney = 0M;
                        smsTemplateParameter.intTempPoint = 0;
                        smsTemplateParameter.intPoint = Convert.ToInt32(dtMem.Rows[i]["MemPoint"]);
                        smsTemplateParameter.OldLevelID = Convert.ToInt32(dtMem.Rows[i]["MemLevelID"]);
                        smsTemplateParameter.NewLevelID = Convert.ToInt32(dtMem.Rows[i]["MemLevelID"]);
                        smsTemplateParameter.MemBirthday = Convert.ToDateTime(dtMem.Rows[i]["MemBirthday"]);
                        smsTemplateParameter.MemPastTime = Convert.ToDateTime(dtMem.Rows[i]["MemPastTime"]);
                        string strSendContent = SMSInfo.GetSendContent(10, smsTemplateParameter, 1);
                        if (SMSInfo.Send_GXSMS(false, dtMem.Rows[i]["MemMobile"].ToString(), strSendContent, ""))
                        {
                            Chain.Model.SmsLog modelSms = new Chain.Model.SmsLog();
                            modelSms.SmsMemID = Convert.ToInt32(dtMem.Rows[i]["MemID"]);
                            modelSms.SmsMobile = dtMem.Rows[i]["MemMobile"].ToString();
                            modelSms.SmsContent = strSendContent;
                            modelSms.SmsTime = DateTime.Now;
                            modelSms.SmsShopID = 1;
                            modelSms.SmsUserID = 1;
                            modelSms.SmsAmount = PubFunction.GetSmsAmount(strSendContent);
                            modelSms.SmsAllAmount = modelSms.SmsAmount;
                            new Chain.BLL.SmsLog().Add(modelSms);
                            Chain.Model.MemberSMSRemindLog MemberSMSRemindLogModel = new Chain.Model.MemberSMSRemindLog();
                            MemberSMSRemindLogModel.MemberSMSRemindMemID = Convert.ToInt32(dtMem.Rows[i]["MemID"]);
                            MemberSMSRemindLogModel.MemberSMSRemindMobile = dtMem.Rows[i]["MemMobile"].ToString();
                            MemberSMSRemindLogModel.MemberSMSRemindContent = strSendContent;
                            MemberSMSRemindLogModel.MemberSMSRemindShopID = 1;
                            MemberSMSRemindLogModel.MemberSMSRemindTime = DateTime.Now;
                            MemberSMSRemindLogModel.MemberSMSRemindUserID = 1;
                            MemberSMSRemindLogModel.MemberSMSRemindAmount = PubFunction.GetSmsAmount(strSendContent);
                            MemberSMSRemindLogModel.MemberSMSRemindAllAmount = modelSms.SmsAmount;
                            MemberSMSRemindLogModel.MemberSMSRemindType = 1;
                            MemberSMSRemindLogModel.MemberSMSRemindBirthday = Convert.ToDateTime(dtMem.Rows[i]["MemBirthday"]);
                            MemberSMSRemindLogBll.Add(MemberSMSRemindLogModel);
                        }
                    }
                }
            }
        }
    }
}

